package com.tang.lts.core.nio;

import com.tang.lts.core.nio.channel.ChannelInitializer;
import com.tang.lts.core.nio.codec.CodecFactory;
import com.tang.lts.core.nio.codec.Decoder;
import com.tang.lts.core.nio.codec.Encoder;
import com.tang.lts.core.nio.config.NioServerConfig;
import com.tang.lts.core.nio.handler.EventHandler;

import java.net.InetSocketAddress;

/**
 * @author Tang
 * @classname NioServerTest
 * @description [  ]
 * @date 2022/5/12 22:59
 */
public class NioServerTest {

    public static void main(String[] args) {

        NioServerConfig serverConfig = new NioServerConfig();
        serverConfig.setBacklog(65536);
        serverConfig.setReuseAddress(true);
        serverConfig.setTcpNoDelay(true);

        NioServer nioServer = new NioServer(serverConfig, new EventHandler(), new ChannelInitializer() {

            @Override
            protected Decoder getDecoder() {
                return CodecFactory.decoder;
            }

            @Override
            protected Encoder getEncoder() {
                return CodecFactory.encoder;
            }

        });

        nioServer.bind(new InetSocketAddress(8888));

        while (true) {
            try {
                Thread.sleep(Integer.MAX_VALUE);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }

}